<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">派费考核报表</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form1"
            style="
              display: flex;
              flex-wrap: wrap;
              margin-top: 24px;
              justify-content: space-between;
            "
            :model="form"
            label-width="80px"
          >
            <el-form-item class="text" label="网点">
              <el-select
                v-model="form.networkName"
                :disabled="true"
                placeholder="辽宁盘锦公司"
                style="width: 286px"
              >
                <el-option label="辽宁盘锦公司" value="1" />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="承包区">
              <el-select
                v-model="form.networkNameId"
                class="input"
                placeholder="请选择"
                style="width: 286px"
              >
                <el-option
                  v-for="item in ShowCoverAreaList"
                  :key="item.id"
                  :label="item.networkName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="费用科目">
              <el-select
                v-model="form.feeSubject"
                class="input"
                placeholder="请选择"
                style="width: 286px"
              >
                <el-option label="签收考核费暂扣" value="1" />
                <el-option label="综合KPI奖励派费" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item
              class="text"
              style="margin-right: 63px"
              label="收付类型"
            >
              <el-select
                v-model="form.collectPayType"
                class="input"
                placeholder="请选择"
                style="width: 286px"
              >
                <el-option label="应收" value="1" />
                <el-option label="应付" value="2" />
              </el-select>
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <elbutton :obj="form" @dj="khClear" />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            :rules="rules"
            style="
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 1188px;
              "
            >
              <el-form-item class="text" label="汇总层级">
                <el-select
                  v-model="form.collectLevel"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="网点" value="1" />
                  <el-option label="承包区" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item
                prop="value"
                style="margin-left: 0"
                class="text"
                label="日期"
              >
                <el-date-picker
                  v-model="form.value"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  style="width: 698px"
                  @change="changeTime"
                />
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"
                  ><i class="el-icon-upload2" />导出</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable :loading="loading" :data="tableData" :th="th">
          <template v-slot:before-columns>
            <el-table-column
              v-if="tableData.length > 0"
              label="序号"
              type="index"
              :index="table_index"
              width="80"
              align="center"
            />
          </template>
        </elltable>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-top: 51px;
          "
        >
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <pagination
              :current-page="current"
              :page-size="10"
              :total="+total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { PaiFeeKhApi, ShowCoverAreaApi } from "@/api/HqFinancePanel";

export default {
  components: {},
  data() {
    return {
      rules: {
        value: [{ required: true, message: "请选择日期", trigger: "change" }],
      },
      loading: false,
      id: "1",
      ProvinceList: [], // 省
      cityList: [], // 市
      value: "",
      form: {
        networkName: "辽宁盘锦公司",
        collectLevel: "",
        collectPayType: "",
        endTime: "",
        feeSubject: "",
        networkNameId: "",
        pageDate: {
          pageNum: 1,
          pageSize: 10,
        },
        startTime: "",
      },
      mxForm: {
        destinationProvince: "",
        destinationCity: "",
      },
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      ShowCoverAreaList: [], // 承包区列表
      th: [],
    };
  },

  computed: {},

  created() {
    this.ShowCoverArea();
  },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val;
      this.onSubmit();
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val;
      this.onSubmit();
    },
    // 序号
    table_index(index) {
      return (
        (this.form.pageDate.pageNum - 1) * this.form.pageDate.pageSize +
        index +
        1
      );
    },
    // 承包区
    async ShowCoverArea() {
      const res = await ShowCoverAreaApi();
      this.ShowCoverAreaList = res.data;
    },
    // 选择时间
    changeTime(value) {
      this.form.startTime = value[0];
      this.form.endTime = value[1];
    },
    // 查询
    async onSubmit() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          const res = await PaiFeeKhApi(this.form);
          this.loading = false;
          if (res.code === 200) {
            this.tableData = res.data.list.data;
            this.total = res.data.list.total;
            this.current = res.data.list.current;
            this.pages = res.data.list.pages;
            this.th = res.data.fields;
          } else {
            this.tableData = [];
            this.total = 0;
            this.current = 1;
            this.pages = 10;
          }
        } else {
          return false;
        }
      });
    },
    // 重置
    khClear(aaa) {
      console.log(aaa);
      this.form = aaa;
    },
  },
};
</script>
<style scoped lang="scss">
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: "";
    width: 62px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
